const app = getApp();

// setData数据:
// isLocation,//是否定位状态

function initLocation() {

}

function getLocation() {
  const that = this;
  wx.getLocation({
    type: 'gcj02',
    success(res) {
      app.infoLog("localtion success ====>", res)
      that.setData({
        isLocation:true,
        lat:res.latitude,
        long:res.longitude,
      })
      if (that.succLocation) that.succLocation(res);
    },
    fail: function(res) {
      app.errorLog("localtion error ====>", res);
      that.setData({
        isLocation: false,
      })
      if (that.failLocation) that.failLocation(res);
    },
    complete:function(res){
      if (that.completeLocation) that.completeLocation(res);
    }
  })
}

function openSetting() {
  const that = this;
  wx.openSetting({
    success: function(res) {
      if (res.authSetting["scope.userLocation"]) {
        that.getLocation();
      }else{
        that.setData({
          isLocation: false,
        })
      }
    },
    fail: function(res) {
      app.errorLog("openSetting error ====>", res)
    }
  })
}

export default {
  initLocation,
  getLocation,
  openSetting,
}